package com.z1.core.utils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateUtil {

	public static void main(String[] args) {
	}

	/**
	 * 判断当前时间是否处于allowTimeSpan所表示的时间段内,24小时制
	 * 10:12:12-15:23:14;03:23:34-09:32:12
	 * @param allowTimeSpan
	 * @return
	 */
	public static boolean isBelongTimeSpan(String allowTimeSpan) {
		if (null == allowTimeSpan || allowTimeSpan.equals("")) {
			return false;
		}
		
		Date now = null;
		Date beginTime = null;
		Date endTime = null;
		SimpleDateFormat df = new SimpleDateFormat("HH:mm:SS");// 设置日期格式

		String regs[] = allowTimeSpan.split(";");
		try {
			now = df.parse(df.format(new Date()));
			beginTime = df.parse(regs[0]);
			endTime = df.parse(regs[1]);
			if(belongCalendar(now, beginTime, endTime)) {
				return true;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	private static boolean belongCalendar(Date nowTime, Date beginTime, Date endTime) {
		Calendar date = Calendar.getInstance();
		date.setTime(nowTime);

		Calendar begin = Calendar.getInstance();
		begin.setTime(beginTime);

		Calendar end = Calendar.getInstance();
		end.setTime(endTime);

		if (date.after(begin) && date.before(end)) {
			return true;
		} else {
			return false;
		}
	}
}
